﻿using UnityEngine;
using System.Collections;

public class CamerFollower : MonoBehaviour
{

    Transform target;
    public float smooth = 0.1f;

    Vector3 offsetPos;
    void Start()
    {
        target = GameObject.FindGameObjectWithTag("Player").transform;
        offsetPos = transform.position;
        offsetPos.x = target.position.x - transform.position.x;

    }

    // Update is called once per frame
    void Update()
    {
        if (target)
        {
            var targetPos = new Vector3(target.position.x - offsetPos.x, offsetPos.y, offsetPos.z);
            transform.position = Vector3.Lerp(transform.position, targetPos, smooth);
        }
    }
}
